'''
Created on Feb 8, 2013

@author: Al Campelo
'''
import urllib
import json

def fetch_thing(url, params, method):
    params = urllib.urlencode(params)
    if method=='POST':
        f = urllib.urlopen(url, params)
    else:
        f = urllib.urlopen(url+'?'+params)
    return (f.read(), f.code)


content, response_code = fetch_thing(
                              'http://www.faroo.com/api', 
                              { 'q': 'animal', 'start':1,'length':200,'l':'en','src':'web','i':'false','f':'json'}, 
                              'GET'
                         )
search_results = json.loads(content)

results = search_results['results']

title = []

for i, elem in map(None, range(len(results)), results):
    title.insert(i,elem['title'])



for i, elem in map(None, range(len(title)), title):
    if 'wikipedia' in title[i] or 'Wikipedia' in title[i]:
        print(title[i])
